package net.wanho.controller;

import lombok.RequiredArgsConstructor;
import net.wanho.service.CaptchaService;
import net.wanho.service.LoginService;
import net.wanho.util.CurrentUtil;
import net.wanho.vo.CaptchaVo;
import net.wanho.vo.LoginUserDTO;
import net.wanho.vo.LoginUserVo;
import net.wanho.vo.R;
import org.springframework.web.bind.annotation.*;

/**
 * Author：汤小洋
 * Date：2024-10-18 16:17
 * Description：<描述>
 */
@RestController
@RequiredArgsConstructor
public class LoginController {

    private final CaptchaService captchaService;
    private final LoginService loginService;

    @GetMapping("/captchaImage")
    public R captchaImage(){
        CaptchaVo captchaVo = captchaService.captcha();
        return R.success(captchaVo);
    }

    @PostMapping("/login")
    public R login(@RequestBody LoginUserDTO loginUserDTO){
        String token = loginService.login(loginUserDTO);
        return R.success("登录成功！", token);
    }

    @GetMapping("/hello")
    public R hello(){
        return R.success("hello");
    }

    @GetMapping("/curr-user")
    public R currUser(){
        LoginUserVo loginUserVo =  loginService.getCurrentUser();
        return R.success(loginUserVo);
    }

    @DeleteMapping("/logout")
    public R logout(){
        CurrentUtil.removeUserId();
        return R.success();
    }

}
